﻿using UnityEngine;
using System.Collections;

public class SoundManagerCommon : MonoBehaviour {

	private static SoundManagerCommon instance;
	
	// Effect Sound
	
	public AudioClip [] BGMList;
	public AudioClip[] soundList;
	public static bool isCreated;
	public float bgmVolumeScale = 1.0f;
	
	public static SoundManagerCommon Instance{
		get{
			return instance;
		}
	}
	
	void Start()
	{
	}
	
	void Awake()
	{
		
        if (isCreated)
        {
            Destroy(gameObject);
        }
        else
        {
            DontDestroyOnLoad(gameObject);
			instance = this;
            isCreated = true;
		}
	}
	
	public void PlaySound(int index)
	{
		Play_Effect_Sound(soundList[index]);
	}
	
	public void Play_Effect_Sound(AudioClip clip)
	{
		if(clip != null) {
			//glog.debug ("play sound");
			audio.PlayOneShot(clip);
		}
	}

	public void PlayBGM( int index)
    {
	    audio.clip = BGMList[index];
	    //audio.volume = volumeScale;
		audio.loop = true;
		audio.Play();
    }	
    
	public void StopBGM()
    {
        audio.Stop();
    }
	
	public void BGMVolumeUp()
	{
		bgmVolumeScale += 0.1f;
		if(bgmVolumeScale>1.0f)
			bgmVolumeScale = 1.0f;
		audio.volume = bgmVolumeScale;
	}
	public void BGMVolumeDown()
	{
		bgmVolumeScale -= 0.1f;
		if(bgmVolumeScale<0.0f)
			bgmVolumeScale = 0.0f;		
		audio.volume = bgmVolumeScale;
	}
}
